﻿<UserControl x:Class="YALV.View.Components.RecentFilesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            xmlns:pinlvw="clr-namespace:MRU.View;assembly=MRU"        
            xmlns:hyperl="clr-namespace:Hyperlink;assembly=MRU"

            xmlns:ellipsiedTxtBlock="clr-namespace:MRU.PathTrimmingTextBlock;assembly=MRU"

             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
  <Grid>
    <Grid.Resources>
    </Grid.Resources>
    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <pinlvw:PinableListView Margin="0"
                            AllowDrop="False"
                            SelectionMode="Single"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            SnapsToDevicePixels="True"
                            HorizontalContentAlignment="Stretch"
                            BorderThickness="0"
                            ItemsSource="{Binding ListOfMRUEntries}"
                            pinlvw:ListViewColumns.Stretch="true"
                            Background="Transparent"
                            Name="PinnedList"
                            Grid.Row="1">
      <pinlvw:PinableListView.View>
        <GridView>
          <GridView.ColumnHeaderContainerStyle>
            <!-- To hide the header of a ListView you can modify the Visibility property of the ColumnHeaderContainer by overriding the style. -->
            <Style>
              <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
            </Style>
          </GridView.ColumnHeaderContainerStyle>
          <GridViewColumn Width="32">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <Grid>
                  <!-- Pin/Unpin column -->
                  <pinlvw:PinnableCheckbox Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pinlvw:PinableListView}}, Path=DataContext.CommandPinUnpin}"
                                           CommandParameter="{Binding}"
                                           IsChecked="{Binding IsPinned, Mode=OneWay}">
                    <CheckBox.Visibility>
                      <MultiBinding Converter="{pinlvw:BoolOrToVisibilityConverter}">
                        <Binding Path="IsMouseOverListViewItem" RelativeSource="{RelativeSource AncestorType={x:Type pinlvw:PinableListViewItem}}" />
                        <Binding Path="IsChecked" RelativeSource="{RelativeSource Self}" />
                      </MultiBinding>
                    </CheckBox.Visibility>
                  </pinlvw:PinnableCheckbox>
                </Grid>
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
          <GridViewColumn >
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <Grid>
                  <hyperl:FileHyperlink Text="{Binding PathFileName, Mode=OneWay}"
                                          NavigateUri="{Binding PathFileName, Mode=OneWay}"
                                          HorizontalAlignment="Stretch" VerticalAlignment="Center">
                    <hyperl:FileHyperlink.Style>
                      <Style TargetType="{x:Type hyperl:FileHyperlink}">
                        <Setter Property="SnapsToDevicePixels" Value="True"/>
                        <Setter Property="ContextMenu">
                          <Setter.Value>
                            <ContextMenu>
                              <MenuItem Header="Copy Url to Clipboard"
                                      Command="{x:Static hyperl:FileHyperlink.CopyUri}"
                                      CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                                      Margin="3" />

                              <MenuItem Header="Open"
                                        Command="{Binding Parent.CommandLoadFile}"                            
                                        CommandParameter="{Binding PathFileName}"
                                        Margin="3" />

                              <MenuItem Header="Open with Windows Application..."
                                      Command="{x:Static hyperl:FileHyperlink.NavigateToUri}"
                                      CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                                      Margin="3" />

                              <MenuItem Header="Open containing folder"
                                      Command="{x:Static hyperl:FileHyperlink.OpenContainingFolder}"
                                      CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                                      Margin="3" />
                              <Separator />

                              <MenuItem Header="Remove"
                                        Command="{Binding Parent.CommandRemoveMruEntry}"
                                        CommandParameter="{Binding}"
                                        Margin="3" />

                            </ContextMenu>
                          </Setter.Value>
                        </Setter>
                        <Setter Property="Template">
                          <Setter.Value>
                            <ControlTemplate TargetType="{x:Type hyperl:FileHyperlink}">
                              <TextBlock ToolTip="{Binding ElementName=PART_Hyperlink, Path=NavigateUri}" HorizontalAlignment="Stretch">
                                <TextBlock.InputBindings>
                                  <KeyBinding Key="C" Modifiers="Ctrl"
                                                      Command="{x:Static hyperl:FileHyperlink.CopyUri}"
                                                      CommandParameter="{Binding ElementName=PART_Hyperlink, Path=NavigateUri}"/>
                                </TextBlock.InputBindings>

                                <!-- NavigateUri="{Binding Path=NavigateUri, RelativeSource={RelativeSource FindAncestor, AncestorType=hyperl:FileHyperlink, AncestorLevel=1}}" -->
                            <Hyperlink Name="PART_Hyperlink"
                                       
                                       Command="{Binding Parent.CommandLoadFile}"
                                       CommandParameter="{Binding Path=NavigateUri, RelativeSource={RelativeSource FindAncestor, AncestorType=hyperl:FileHyperlink, AncestorLevel=1}}"
                                       >
                              <Hyperlink.Style>
                                <!-- Change resource to show underline on mouseover only -->
                                <Style TargetType="{x:Type Hyperlink}">
                                  <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="true">
                                      <Setter Property="TextDecorations" Value="Underline" />
                                      <Setter Property="Foreground" Value="{DynamicResource HyperlinkForeground}" />
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                      <Setter Property="Foreground" Value="{DynamicResource HyperlinkForegroundDisabled}" />
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="true">
                                      <Setter Property="Cursor" Value="Hand" />
                                    </Trigger>
                                  </Style.Triggers>
                                  <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
                                  <Setter Property="Foreground" Value="{DynamicResource HyperlinkForeground}" />
                                </Style>
                              </Hyperlink.Style>
                              <!-- Moved link to event handler RequestNavigate="Hyperlink_RequestNavigate" to code behind -->
                              <!-- TextBlock Text="{Binding Path=Text, RelativeSource={RelativeSource FindAncestor, AncestorType=hyperl:FileHyperlink, AncestorLevel=1}}" / -->
                              <ellipsiedTxtBlock:PathTrimmingTextBlock Path="{Binding Text, RelativeSource={RelativeSource FindAncestor, AncestorType=hyperl:FileHyperlink, AncestorLevel=1}}" />
                          </Hyperlink>
                              </TextBlock>
                            </ControlTemplate>
                          </Setter.Value>
                        </Setter>
                      </Style>
                    </hyperl:FileHyperlink.Style>
                  </hyperl:FileHyperlink>
                </Grid>
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
        </GridView>
      </pinlvw:PinableListView.View>
    </pinlvw:PinableListView>
  </Grid>
</UserControl>
